package com.qf.controller;

import com.qf.pojo.Category;
import com.qf.service.CategoryService;
import com.qf.service.impl.CategoryServiceImpl;
import com.qf.utils.JsonUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

/**
 * 分类信息的后端访问地址
 */
@WebServlet("/category")
public class CategoryServlet extends BaseServlet {

    /**
     * 获取商品分类信息
     * @param request 请求对象
     * @param response 响应对象
     */
    public void getAllCategory(HttpServletRequest request,HttpServletResponse response) throws IOException {

        //直接访问分类业务接口
        CategoryService categoryService = new CategoryServiceImpl() ;
        List<Category> allCaregorys = categoryService.getAllCaregorys();
        //response.setContentType("application/json;charset=utf-8");
        //将集合对象转换成json,响应给前端
        String jsonStr = JsonUtils.list2json(allCaregorys);
        //[{},{}]
        //响应
        response.getWriter().write(jsonStr);
    }
}
